//
//  HomeTbvCell.m
//  Ten
//
//  Created by anfuer on 2018/8/14.
//  Copyright © 2018年 xg韦. All rights reserved.
//

#import "HomeTbvCell.h"
#import "MenuCollCell.h"
#import "ELCVFlowLayout.h"
#import "UIButton+WebCache.h"
@interface HomeTbvCell()
{
    NSArray*colldata;
}
@end
@implementation HomeTbvCell

- (void)awakeFromNib {
    [super awakeFromNib];
     [_collview registerClass:[MenuCollCell class] forCellWithReuseIdentifier:@"MenuCollCell"];
    [[_imgbtno imageView] setContentMode:UIViewContentModeScaleAspectFit];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (instancetype)CellWithTableView:(UITableView *)tableView
{
    static NSString *reuseId = @"HomeTbvCell";
    HomeTbvCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"HomeTbvCell" owner:nil options:nil] lastObject];
        
    }
    
    
    return cell;
    
    
}
#pragma mark -- UICollectionViewDataSource 数据源方法
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake([MyUtils GetWidthFromString:colldata[indexPath.row] Font:[UIFont systemFontOfSize:12] Height:25]+20 ,25);
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    
    return colldata.count;
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"MenuCollCell";
    MenuCollCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    [cell.btno setTitle:colldata[indexPath.row] forState:UIControlStateNormal];
   
    return cell;
}

#pragma mark --UICollectionViewDelegate

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
  
//    [MyUtils collviewSelidex:name_str toVc:[MyUtils getCurrentVC] andShopInfo:nil];
}

//设置垂直间距,默认的垂直和水平间距都是10
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}
//设置水平间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 5;
}


-(void)Cellinit:(NSDictionary*)dic
{
    
    if ([dic[@"welfare"] isKindOfClass:[NSArray class]]) {
        colldata=dic[@"welfare"];
    }else
    {
        colldata= [WXGStr(dic[@"welfare"]) componentsSeparatedByString:@","];
    }

    [_collview reloadData];
    _collH.constant= _collview.collectionViewLayout.collectionViewContentSize.height+15;
    _lb1.text=WXGStr(dic[@"title"]);
    _lb2.text=[NSString stringWithFormat:@"￥%@/%@",dic[@"salary"],[WXGStr(dic[@"salary_type"])isEqualToString:@"2"]?@"月":@"日"];
    _lb3.text=[NSString stringWithFormat:@"工作地址:%@",dic[@"address"]];
    if (WXGStr(dic[@"add_time"]).length==10) {
         _lb4.text= [FuncPublic time:dic[@"add_time"]];
    }else
    {
       _lb4.text=WXGStr(dic[@"add_time"]);
    }
    [_imgbtno sd_setImageWithURL:[dic[@"company"][@"logo"]formatUrl] forState:UIControlStateNormal placeholderImage:WXGImage(@"zhanwei")];
      _lb5.text=WXGStr(dic[@"company"][@"name"]);
}

@end
